package org.govhack.okcapital.controllers;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.govhack.okcapital.model.Dataset;
import org.govhack.okcapital.services.CsvDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Controller for Datasets
 * @author Josh Vote
 *
 */
@Controller
public class DatasetController extends BaseController {

    private final Log log = LogFactory.getLog(getClass());
    
    CsvDataService dataService;
    
    @Autowired
    public DatasetController(CsvDataService dataService) {
        this.dataService = dataService;
    }
    
    /**
     * Gets every dataset available for weighting as a JSON response
     * @return
     */
    @RequestMapping("getAllDatasets.do")
    public ModelAndView getAllDatasets() {
        //Skeleton code
        /*List<Dataset> fakeData = Arrays.asList(
                new Dataset("urn:foo1", "fake-data-1", "fake-description", 1),
                new Dataset("urn:foo2", "fake-data-2", "fake-description", 2),
                new Dataset("urn:foo3", "fake-data-3", "fake-description", 3),
                new Dataset("urn:foo4", "fake-data-4", "fake-description", 4),
                new Dataset("urn:foo5", "fake-data-5", "fake-description", 5));*/
        return generateJsonResponse(true, dataService.getDatasets());
    }
}
